﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

using Perseus;

namespace Hetymine.Executioner.Commands {
    public static class Helper {
        public static List<CommandInfo> Commands(XElement element) {
            List<CommandInfo> commandList = new List<CommandInfo>();

            var commands = from cmd in element.Elements("Command")
                           select cmd;

            foreach (var cmd in commands) {
                commandList.Add(new CommandInfo(cmd));
            }

            return commandList;
        }
        public static List<string> Inputs(XAttribute attribute, string[] allowedInputs) {
            // Audio and string supported
            List<string> inputsList = new List<string>();
            
            if (attribute == null) {
                inputsList.Add(allowedInputs[0]);
            }
            else {
                string[] inputs = PString.Split(
                    attribute.Value,
                    ",", SplitOptions.Trim
                );

                foreach (string i in inputs) {
                    if (i.IsIn(allowedInputs)) {
                        inputsList.Add(i);
                    }
                }
            }

            return inputsList;
        }
    }
}
